package com.xhui.vimarket.zkplus.zul.attr.mod.impl;t java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.directwebremoting.util.Logger;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Div;
import org.zkoss.zul.Hbox;
import org.zkoss.zul.Label;
com.xhui.vimarket.zkplusui.vimarket.zkplus.zul.attrcom.xhui.vimarket.zkplusrt com.xhui.vimarket.zkplus.zul.acom.xhui.vimarket.zkplusst;
import com.xhui.vimarket.zkpcom.xhui.vimarket.zkplusan.AttrTmpl;
import com.xhui.vimarket.zkplus.zul.attr.mod.AttrCompUticom.xhui.vimarket.zkplus版权：福富软件 版权所有 (c) 2010
 * @文件：com.xhui.vimarket.zkplus.zul.attr.mod.impl.AttrNullComp.java
 * @所含类：
 * @author: wuyx
 * @version: V1.0
 * @see:
 * @创建日期：2010-12-20
 * @功能说明：属性控件接口
 * @修改记录： =============================================================<br>
 *        日期:2010-12-20 创建
 *        =============================================================<br>
 */
public final class AttrNullValComp extends AttrBaseComp {
    
    /**
     * 实例.
     */
    private static AttrNullValComp inst   = new AttrNullValComp();
    
    /**
     * 日志.
     */
    private static Logger          logger = Logger.getLogger(AttrNullValComp.class);
    
    /**
     * 构造函数. 
     */
    private AttrNullValComp() {
    }
    
    /**
     * 获取实例.
     * 
     * @return AttrBaseComp
     */
    public static AttrNullValComp instance() {
        return AttrNullValComp.inst;
    }
    
    /**
     * 生成组件.
     * 
     * @param attrExt 组件控件
     * @param attrTmpl 组件模板
     * @param comp 显示容器组件
     */
    @Override
    public void create(final AttrExt attrExt, final AttrTmpl attrTmpl, final Component comp) {
        super.create(attrExt, attrTmpl, comp);
        // 如果是配置状态下,进行界面显示展示:
        if (attrExt.isSettingPreview()) {
            // panel
            final Hbox hbox = new Hbox();
            hbox.setAttribute(AttrBaseComp.COMP_MODE, attrTmpl.getDisplayMode());
            hbox.setAttribute(AttrBaseComp.COMP_ATTRID, attrTmpl.getAttrId());
            hbox.setWidth("100%");
            final Label label = new Label(attrTmpl.getName());
            // add to zul
            hbox.setParent(comp);
            label.setParent(hbox);
            if (attrTmpl.getHint() != null) {
                hbox.setTooltiptext(attrTmpl.getHint());
            }
            // comp log
            if (AttrNullValComp.logger.isDebugEnabled()) {
                attrExt.appendInnerComp("<hbox width=\"100%\">");
                attrExt.appendInnerCompAttr(AttrBaseComp.COMP_MODE, attrTmpl.getDisplayMode());
                attrExt.appendInnerCompAttr(AttrBaseComp.COMP_ATTRID, "" + attrTmpl.getAttrId());
                attrExt.appendInnerComp("<label value=\"");
                attrExt.appendInnerComp(attrTmpl.getName());
                attrExt.appendInnerComp("\" />");
                attrExt.appendInnerComp("</hbox>");
            }
        } else {
//            final String strWithComposer = attrExt.getAttrAda().getAttrTmplCompStr(
//                attrTmpl.getDisplayMode(), attrTmpl, attrTmpl.getParam2(), null, null);
//            final Div div = (Div) Executions.createComponentsDirectly(strWithComposer, null,
//                rootdiv, null);
            final Div rootdiv = new Div();
            rootdiv.setParent(comp);
            final Div div = (Div) attrExt.getAttrAda().getAttrTmplCompStr(
                attrTmpl.getDisplayMode(), attrTmpl, attrTmpl.getParam2(), null, null,rootdiv);
            //div.setParent(rootdiv);
            rootdiv.setAttribute(AttrBaseComp.COMP_MODE, attrTmpl.getDisplayMode());
            rootdiv.setAttribute(AttrBaseComp.COMP_ATTRID, attrTmpl.getAttrId());
            rootdiv.setAttribute(AttrBaseComp.COMP_STYLE, attrTmpl.getDisplayStyle());
            rootdiv.setAttribute(AttrBaseComp.COMP_ATTRID, attrTmpl.getAttrId());
            rootdiv.setAttribute(AttrBaseComp.COMP_JAVACODE, attrTmpl.getJavaCode());
            rootdiv.setAttribute(AttrBaseComp.COMP_PARAM1, attrTmpl.getParam1());
            rootdiv.setAttribute(AttrBaseComp.COMP_PARAM2, attrTmpl.getParam2());
            rootdiv.setAttribute(AttrBaseComp.COMP_CANTNULL, AttrCompUtil.getStrCantNull(attrTmpl
                .isCantNull()));
            div.setAttribute(AttrBaseComp.COMP_MODE, attrTmpl.getDisplayMode());
            div.setAttribute(AttrBaseComp.COMP_ATTRID, attrTmpl.getAttrId());
            div.setAttribute(AttrBaseComp.COMP_STYLE, attrTmpl.getDisplayStyle());
            div.setAttribute(AttrBaseComp.COMP_ATTRID, attrTmpl.getAttrId());
            div.setAttribute(AttrBaseComp.COMP_JAVACODE, attrTmpl.getJavaCode());
            div.setAttribute(AttrBaseComp.COMP_PARAM1, attrTmpl.getParam1());
            div.setAttribute(AttrBaseComp.COMP_PARAM2, attrTmpl.getParam2());
            div.setAttribute(AttrBaseComp.COMP_CANTNULL, AttrCompUtil.getStrCantNull(attrTmpl
                .isCantNull()));
        }
    }
    
    /**
     * 设置值.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     * @param attrInstList 属性实例
     */
    @Override
    public void setValue(final AttrExt attrExt, final Component comp,
        final List<AttrInst> attrInstList,final Map<String, Integer> attrViewMap) {
        super.setValue(attrExt, comp, attrInstList,attrViewMap);
        // 触发事件进行值删除
        Events.sendEvent(Events.ON_CHANGE, comp.getFirstChild(), null);
    }
    
    /**
     * 获取值.
     * 
     * @param attrExt 组件控件
     * @param comp 组件
     * @return ArrayList<AttrInst>
     */
    @Override
    public ArrayList<AttrInst> getValue(final AttrExt attrExt, final Component comp) {
        super.getValue(attrExt, comp);
        return null;
    }
    
    /**
     * 取空值属性实例.
     * 
     * @param attrExt 组件控件
     * @param attrTmpl 模板
     * @return ArrayList<AttrInst>
     */
    @Override
    public ArrayList<AttrInst> getNullValue(final AttrExt attrExt, final AttrTmpl attrTmpl) {
        super.getNullValue(attrExt, attrTmpl);
        final ArrayList<AttrInst> retList = new ArrayList<AttrInst>();
        final AttrInst attrInst = attrExt.newAttrInst();
        attrInst.setAttrId(attrTmpl.getAttrId());
        attrInst.setJavaCode(attrTmpl.getJavaCode());
        retList.add(attrInst);
        return retList;
    }
    
}
